<template>
	<view class="content">
		<nav-header bgColor="bg-custom-color" :isBack="true">
			<block slot="content">{{$t('order.lineUpOrder')}}</block>
		</nav-header>
		<view class="form-div">
			<view class="cu-form-group">
				<view class="title">充值方式</view>
				<button class='cu-btn  shadow' :class="entity.opt_type == 0?'bg-tm':''">GHMI</button>
				<button class='cu-btn shadow' :class="entity.opt_type == 1?'bg-tm':''">GUSD</button>
			</view>
			<view class="cu-form-group">
				<view class="title">充值金额</view>
				<input name="ghmi" v-model="entity.cash_count" placeholder="输入充值金额" />
			</view>
			<view class="cu-form-group">
				<view class="title">可兑换算力(USDT)</view>
				<view>{{$common.numFilter(entity.cash_count / bili)}}</view>
			</view>
		</view>
		<view class="padding flex flex-direction">
			<button class="cu-btn bg-tm lg" :style="is?'':'background-color: var(--darkGray);'" @tap="tijiao">{{is?'充值':'提交中'}}</button>
		</view>
	</view>
</template>

<script>
	var t;
	export default {
		data() {
			return {
				datas: {},
				entity: {
					opt_type: 0,
					cash_count: '',
				},
				userInfo: null,
				bili: 1,
				is: true,
			}
		},
		onLoad() {
			t = this;
			this.$i18n.locale = t.$common.localRead("local")
			t.userInfo = $common.getUser()
			if (!t.userInfo) {
				$common.notLoginUser()
			}
			console.info(t.userInfo)
			// t.getData();
			t.getHuilv()

			t.modalName = 'Modal'
			setTimeout(function() {
				t.loading = true
			}, 500)
		},
		methods: {
			tabSelect(e) {
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60
			},
			getData: function() {
				this.$fetch.request('orderInfo/getOrderList', {
					addUserId: t.userInfo.id,
					orderState: 50
				}).then((res) => {
					console.info(res)
					if (res.code == 200) {
						// this.list = res.data.entityList
						t.datas = res.data;
					} else {
						$common.showToast(res.msg);
					}
				}).catch((e) => {})
			},
			getHuilv() {
				t.$fetch.request('api/queryExchange', {
					shortName: 'CNY'
				}).then((res) => {
					console.info(res.data)
					if (res.status == 'success') {
						t.bili = res.data.USDT
						t.bili = 2;
						console.info(t.bili)
					} else {
						$common.showToast(res.message);
						console.info("===获取汇率失败==")
					}
				}).catch((e) => {})
			},
			modalChoose(item) {
				console.info(item);
				if (item.isLock == 1) {
					$common.showToast(t.$t('order.temporarilyOpen'));
					return
				}
				t.entity = item;
				this.modalName = ''
			},
			tijiao: function() {
				// if (t.userInfo.biDianzi < this.entity.typeValue) {
				// 	$common.showToast('GHMI不足');
				// 	return;
				// }
				if (!t.entity.cash_count) {
					$common.showToast('请输入充值金额');
					return;
				}
				if (!t.is) {
					return;
				}
				t.is = !t.is;

				let data = {
					userId: t.userInfo.id,
					cashCount: t.entity.cash_count,
					cashType: 20,
					addUid: t.userInfo.id,
					optType: t.entity.opt_type
				}
				this.$fetch.request('orderInfo/save', data, "POST").then((res) => {
					console.info(res)
					if (res.code == 200) {
						console.info("排单成功")
						// $common.showToast('排单成功');
						t.$common.showToast(t.$t('tip.operationSuccess'))
						t.is = !t.is;
						// $common.toPage('../order/record', 1, 1000)
					} else {
						$common.showToast(res.msg);
						t.is = !t.is;
					}
				}).catch((e) => {})

			},
			hideModal(e) {
				this.modalName = null
			},
		}
	}
</script>

<style>
	.form-div {
		margin: 20px;
		background: white;
	}
</style>
